let Draw = agcim.interactive.draw;
let AgFeatureLayer = agcim.layer.FeatureLayer;
let AgPoint = agcim.geometry.Point;
var agFeatureLayer;
class CoordinatePick {
    constructor() {
        this.viewer = null;
        this.draw = null;
        agFeatureLayer = new AgFeatureLayer(CIM.viewer);
    }
    /**
     * @description: 画点
     * @param {*} viewer 
     * @returns 
     */
    pickAndDrawPoint(viewer,vm) {
        let _this = this;
        return new Promise((resolve, reject) => {
            this.viewer = viewer;
            this.draw = new Draw(viewer);
            this.draw.drawPoint({ show: false }).then(obj => {
                if (agFeatureLayer._entities.length > 0) { agFeatureLayer.removeAll(); }
                let positions = obj.positions;
                var pointOpt = {
                    color: Cesium.Color.CRIMSON,
                    pixelSize: 6,
                    outlineColor: Cesium.Color.WHITE,
                    ouelineWith: 2
                };
                var point = new AgPoint(
                    "agPoint",
                    positions[0],
                    pointOpt
                );
                point.addToLayer(agFeatureLayer);
                let cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
                let long = Cesium.Math.toDegrees(cartographic.longitude).toFixed(8);
                let lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(8);
                let elev = cartographic.height.toFixed(2);
                vm.long = Cesium.Math.toDegrees(cartographic.longitude).toFixed(8);
                vm.lat = lat;
                vm.elev = elev;
                vm.x = positions[0].x;
                vm.y = positions[0].y;
                vm.z = positions[0].y;
                // resolve({
                //     long,
                //     lat,
                //     elev,
                //     x: positions[0].x,
                //     y: positions[0].y,
                //     z: positions[0].z
                // })
                _this.pickAndDrawPoint(viewer,vm);
            })
        })
    }
    dispose() {
        agFeatureLayer.removeAll();
        this.draw.dispose();
    }
}

export default new CoordinatePick();